package com.ll.example.springbootwebdemokotlin.component

import org.springframework.web.servlet.LocaleResolver
import java.util.*
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

/**
 * 可以在链接上携带区域信息
 */
class MyLocaleResolver : LocaleResolver {
    override fun resolveLocale(p0: HttpServletRequest): Locale {
        val s = p0.getParameter("l")
        //取出系统默认的区域解析器
        var locale=Locale.getDefault()
        //如果传入参数不为空，则根据传入的参数生成区域解析器
        s?.let {
            //解析字符串 （样式为 zh_CN）
            val list = it.split("_")
            //生成新的区域解析器
            locale=Locale(list[0],list[1])
        }
        return locale
    }



    override fun setLocale(p0: HttpServletRequest, p1: HttpServletResponse?, p2: Locale?) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }


}